package com.atqinke.designpattern.behavioraltype.responsibility;

/**
 * @BelongsProject: BasicConnection
 * @BelongsPackage: com.atqinke.designpattern.behavioraltype.responsibility
 * @Author: NieHk
 * @CreateTime: 2022-08-28  23:45
 * @Description: 处理者抽象类
 * @Version: 1.0
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;
    protected final static int NUM_MAX = Integer.MAX_VALUE;
    protected final static int NUM_FINITY = (int) (1.0/0); //无穷大
    //该领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    //领导上面还有领导
    private Handler nextHandler;

    //设置请假天数范围 上不封顶
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    //设置请假天数范围
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //设置上级领导
    public void setNextHandler(Handler nextHandler){
        this.nextHandler = nextHandler;
    }

    //提交请假条
    public final void submit(LeaveRequest leave){
        if(0 == leave.getNum()){
            return;
        }

        //如果请假天数达到该领导者的处理要求
        if(leave.getNum() <= this.numEnd) {
            this.handleLeave(leave);
        }else if (null != this.nextHandler){
            //如果还有上级 并且请假天数超过了当前领导的处理范围
                this.nextHandler.submit(leave);//继续提交
        }else {
            System.out.println("请求不合理,驳回!");
        }
    }

    //各级领导处理请假条方法
    protected abstract void handleLeave(LeaveRequest leave);
}
